package com.example.ajax.service.impl;

import com.example.ajax.bean.User;
import com.example.ajax.dao.UserDao;
import com.example.ajax.dao.impl.UserDaoImpl;
import com.example.ajax.service.UserService;
import com.example.ajax.util.Md5Util;
import org.thymeleaf.util.StringUtils;

import java.util.List;

/**
 * @author ddone
 * @date 2024/3/13-12:34
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public List<User> findUserList() {
      return userDao.findUserList();
    }

    @Override
    public int insertUser(User user) {
        return userDao.insertUser(user);
    }

    @Override
    public User findUserById(String userid) {
        return userDao.findUserById(Integer.parseInt(userid));
    }

    @Override
    public int  updateUser(User user) {
        if(StringUtils.isEmpty(user.getPwd())){
            return  userDao.updateUser(user);
        }
        user.setPwd(Md5Util.encode(user.getPwd()));
        return  userDao.updateUser(user);
    }

    @Override
    public int deleteById(String userid) {
        return userDao.deleteById(Integer.parseInt(userid));
    }
}
